package com.xueyi.aixihu.service.impl;

import cn.hutool.core.date.DateUtil;
import com.xueyi.aixihu.constant.*;
import com.xueyi.aixihu.entity.generatedMapper.AxhFinanceDao;
import com.xueyi.aixihu.entity.generatedMapper.AxhFinanceMapper;
import com.xueyi.aixihu.entity.po.AxhFinanceLog;
import com.xueyi.aixihu.entity.po.AxhFinancePo;
import com.xueyi.aixihu.entity.po.DtNewsSort;
import com.xueyi.aixihu.entity.vo.AxhAuditFinanceLogVo;
import com.xueyi.aixihu.entity.vo.DtUsersVo;
import com.xueyi.aixihu.exception.SzException;
import com.xueyi.aixihu.mapper.FinanceAuditMapper;
import com.xueyi.aixihu.mapper.FinanceMapper;
import com.xueyi.aixihu.reqeust.AuditFinanceReq;
import com.xueyi.aixihu.reqeust.FindAuditFinanceDto;
import com.xueyi.aixihu.reqeust.OpenNewsReq;
import com.xueyi.aixihu.reqeust.TableData;
import com.xueyi.aixihu.response.FinanceDetailVo;
import com.xueyi.aixihu.response.FindAuditFinanceVo;
import com.xueyi.aixihu.service.DtNewsService;
import com.xueyi.aixihu.service.FinanceAuditService;
import com.xueyi.aixihu.status.SystemCode;
import com.xueyi.aixihu.utils.MD5Utils;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.StringJoiner;

/**
 * @author lvyi
 * @date : 2023/6/29
 * @Description :
 */
@Service
@AllArgsConstructor
public class FinanceAuditServiceImpl implements FinanceAuditService {

    private final FinanceAuditMapper financeAuditMapper;
    private final AxhFinanceMapper axhFinanceMapper;
    private final AxhFinanceDao axhFinanceDao;
    private final FinanceMapper financeMapper;
    private final DtNewsService dtNewsService;

    /**
     * 是否公开镇级财务公开
     *
     * @param openNewsReq
     * @return
     * @throws SzException
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Boolean openFinanceByZJCW(OpenNewsReq openNewsReq) throws SzException {
        //获取当前登陆用户的信息
        DtUsersVo dtUsersVo = DtUsersVo.findCurrentUser();

        //获取用户的角色 并判断是否是镇财政所所长
        Integer userMaxRole = dtUsersVo.findUserMaxRole();
        if (!userMaxRole.equals(SystemRoleConstant.Z_CZS_SZ) && !userMaxRole.equals(SystemRoleConstant.SUPER_ADMIN)) {
            throw new SzException(SystemCode.USER_JURISDICTION_ERROR, "暂无权限");
        }
        AxhFinanceLog axhFinanceLog = new AxhFinanceLog();

        //执行公开操作
        financeAuditMapper.openFinanceByZJCW(openNewsReq);
        financeAuditMapper.openFinanceByZJCWRecord(openNewsReq, AuditConstant.CW_AUDIT);

        if (openNewsReq.getIsPublic().equals(1)) {
            axhFinanceLog.setRemark("发布");
            axhFinanceLog.setLogContent("【报表审核】用户" + dtUsersVo.getUsername() + "审核了该报表，状态为：已公开");
        } else {
            axhFinanceLog.setRemark("取消发布");
            axhFinanceLog.setLogContent("【报表审核】用户" + dtUsersVo.getUsername() + "审核了该报表，状态为：未公开");
        }
        axhFinanceLog.setFinanceId(openNewsReq.getId());
        axhFinanceLog.setCurrentFinanceStatus(FinanceAuditLogStep.PUBLIC.VAL);
        axhFinanceLog.setCommandUserId(dtUsersVo.getId());
        financeAuditMapper.addAuditLog(axhFinanceLog);

        return Boolean.TRUE;
    }

    /**
     * 审核镇级财务公开
     *
     * @param auditFinanceReq
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Boolean auditFinanceByZJCW(AuditFinanceReq auditFinanceReq) throws SzException {
        //获取当前登陆用户的信息
        DtUsersVo dtUsersVo = DtUsersVo.findCurrentUser();

        //获取用户的角色 并判断是否是镇财政所所长
        Integer userMaxRole = dtUsersVo.findUserMaxRole();
        if (!userMaxRole.equals(SystemRoleConstant.Z_CZS_SZ)) {
            throw new SzException(SystemCode.USER_JURISDICTION_ERROR, "暂无权限");
        }
        AxhFinanceLog axhFinanceLog = new AxhFinanceLog();


        //判断是审核通过还是不通过
        if (auditFinanceReq.getIsConsent().equals(OneLevelAuditConstant.CONSENT)) {
            financeAuditMapper.auditSuccessFinanceByZJCW(auditFinanceReq);
            axhFinanceLog.setRemark("同意");
            axhFinanceLog.setLogContent("【报表审核】用户" + dtUsersVo.getUsername() + "审核了该报表，状态为：已通过");
            financeAuditMapper.auditSuccessFinanceByZJCWRecord(auditFinanceReq, AuditConstant.CW_AUDIT, dtUsersVo.getId());
        } else if (auditFinanceReq.getIsConsent().equals(OneLevelAuditConstant.FAIL)) {
            if (StringUtils.isBlank(auditFinanceReq.getFailMsg())) {
                throw new SzException(SystemCode.QUERY_CHECK_ERROR, "请输入拒绝理由");
            }
            axhFinanceLog.setRemark(auditFinanceReq.getFailMsg());
            axhFinanceLog.setLogContent("【报表审核】用户" + dtUsersVo.getUsername() + "审核了该报表，状态为：驳回");
            financeAuditMapper.auditFailFinanceByZJCW(auditFinanceReq);
            financeAuditMapper.auditFailFinanceRecord(auditFinanceReq, AuditConstant.CW_AUDIT, dtUsersVo.getId(), null);
        }

        axhFinanceLog.setFinanceId(auditFinanceReq.getId());
        axhFinanceLog.setCurrentFinanceStatus(auditFinanceReq.getIsConsent());
        axhFinanceLog.setCommandUserId(dtUsersVo.getId());
        financeAuditMapper.addAuditLog(axhFinanceLog);
        return Boolean.TRUE;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void changeCaoGao(Integer id) throws SzException {

        //获取当前登陆用户的信息
        DtUsersVo dtUsersVo = DtUsersVo.findCurrentUser();

        AxhFinancePo axhFinancePo = axhFinanceDao.selectByPrimaryKey(id);
        if (!axhFinancePo.getCreateUserId().equals(dtUsersVo.getId())) {
            throw new SzException(SystemCode.QUERY_CHECK_ERROR, "您不能转为草稿！");
        }
        if (!(axhFinancePo.getCurrentStatus().equals(TwoLevelAuditConstant.ONE_FAIL) || axhFinancePo.getCurrentStatus().equals(OneLevelAuditConstant.FAIL))) {
            throw new SzException(SystemCode.QUERY_CHECK_ERROR, "当前状态不能转为草稿！");
        }


        financeAuditMapper.consentOrFailFinance(id,
                null,
                TwoLevelAuditConstant.DRAFT);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void auditFinance(AuditFinanceReq auditFinanceReq) throws SzException {

        //获取当前登陆用户的信息
        DtUsersVo dtUsersVo = DtUsersVo.findCurrentUser();

        //获取用户的角色
        Integer userMaxRole = dtUsersVo.findUserMaxRole();

        if (auditFinanceReq.getIsConsent().equals(0) && !org.springframework.util.StringUtils.hasLength(auditFinanceReq.getFailMsg())) {
            throw new SzException(SystemCode.QUERY_CHECK_ERROR, "请填写拒绝理由");
        } else if (auditFinanceReq.getIsConsent().equals(1)) {
            auditFinanceReq.setFailMsg(null);
        }

        String[] financeIdArr = auditFinanceReq.getIds().split(",");

        for (String id : financeIdArr) {
            int financeId = Integer.parseInt(id);
            // 查询财务报表的基本信息
            AxhFinancePo axhFinance = axhFinanceDao.selectByPrimaryKey(financeId);
            if (axhFinance == null) {
                throw new SzException(SystemCode.QUERY_CHECK_ERROR, "报表查询失败");
            }

            // 查询当前用户是什么角色 ，下一步应该对应的审核状态是否一致
            List<Integer> expectFinanceStatusArr = dtUsersVo.findUserAuditFinanceStatus(userMaxRole, null);
            List<Integer> expectAreaTypeArr = null;
            Integer expectFinanceStatus = null;
            Integer expectFinanceLogStatus = null;
            boolean validate = false;
            if (userMaxRole.equals(SystemRoleConstant.Z_CZS_SZ)) {

                // 判断当前的角色有没有权限审核这个报表
                expectAreaTypeArr = SystemRoleAuditAreaEnum.Z_CZS_SZ.AUDIT_TYPE;
                if (!SystemRoleAuditAreaEnum.Z_CZS_SZ.AUDIT_TYPE.contains(axhFinance.getAreaType())) {
                    throw new SzException(SystemCode.QUERY_CHECK_ERROR, "权限不够..");
                }

                // 判断是居委、社区还是镇
                if (axhFinance.getAreaType().equals(AddressConstant.JW) || axhFinance.getAreaType().equals(AddressConstant.SQ)) {
                    if (!axhFinance.getCurrentStatus().equals(TwoLevelAuditConstant.ONE_CONSENT)) {
                        throw new SzException(SystemCode.QUERY_CHECK_ERROR, "当前报表您不能进行审核（状态还在流转阶段）");
                    }

                    if (auditFinanceReq.getIsConsent().equals(1)) {
                        expectFinanceStatus = TwoLevelAuditConstant.TWO_CONSENT;
                        expectFinanceLogStatus = FinanceAuditLogStep.TWO_LEVEL_CONSENT.VAL;
                    } else {
                        expectFinanceStatus = TwoLevelAuditConstant.TWO_FAIL;
                        expectFinanceLogStatus = FinanceAuditLogStep.TWO_LEVEL_FAIL.VAL;
                    }
                } else {

                    // 镇类型的报表
                    if (!axhFinance.getCurrentStatus().equals(OneLevelAuditConstant.SUBMIT_AUDIT)) {
                        throw new SzException(SystemCode.QUERY_CHECK_ERROR, "当前报表您不能进行审核（状态还在流转阶段）");
                    }


                    if (auditFinanceReq.getIsConsent().equals(1)) {
                        expectFinanceStatus = OneLevelAuditConstant.CONSENT;
                        expectFinanceLogStatus = FinanceAuditLogStep.ONE_LEVEL_CONSENT.VAL;
                    } else {
                        expectFinanceStatus = OneLevelAuditConstant.FAIL;
                        expectFinanceLogStatus = FinanceAuditLogStep.ONE_LEVEL_FAIL.VAL;
                    }

                }

                validate = true;

            } else if (userMaxRole.equals(SystemRoleConstant.Z_JGZ_CY) || userMaxRole.equals(SystemRoleConstant.Z_CZS_CY)) {

                if (userMaxRole.equals(SystemRoleConstant.Z_JGZ_CY)) {
                    expectAreaTypeArr = SystemRoleAuditAreaEnum.Z_JGZ_CY.AUDIT_TYPE;
                } else {
                    expectAreaTypeArr = SystemRoleAuditAreaEnum.Z_CZS_CY.AUDIT_TYPE;
                }

                if (auditFinanceReq.getIsConsent().equals(1)) {
                    expectFinanceStatus = TwoLevelAuditConstant.ONE_CONSENT;
                    expectFinanceLogStatus = FinanceAuditLogStep.ONE_LEVEL_CONSENT.VAL;
                } else {
                    expectFinanceStatus = TwoLevelAuditConstant.ONE_FAIL;
                    expectFinanceLogStatus = FinanceAuditLogStep.ONE_LEVEL_FAIL.VAL;
                }
            } else if (userMaxRole.equals(SystemRoleConstant.Z_JGZ_ZZ)) {
                expectAreaTypeArr = SystemRoleAuditAreaEnum.Z_JGZ_ZZ.AUDIT_TYPE;
                if (auditFinanceReq.getIsConsent().equals(1)) {
                    expectFinanceStatus = TwoLevelAuditConstant.TWO_CONSENT;
                    expectFinanceLogStatus = FinanceAuditLogStep.TWO_LEVEL_CONSENT.VAL;
                } else {
                    expectFinanceStatus = TwoLevelAuditConstant.TWO_FAIL;
                    expectFinanceLogStatus = FinanceAuditLogStep.TWO_LEVEL_FAIL.VAL;

                }
            } else {
                throw new SzException(SystemCode.QUERY_CHECK_ERROR, "当前您的角色并不能进行审核操作");
            }

            if (!validate) {
                validate = true;

                // 判断当前的角色有没有权限审核这个报表
                if (!expectAreaTypeArr.contains(axhFinance.getAreaType())) {
                    throw new SzException(SystemCode.QUERY_CHECK_ERROR, "权限不够..");
                }

                // 判断当前报表的状态是否符合
                if (!expectFinanceStatusArr.contains(axhFinance.getCurrentStatus())) {
                    throw new SzException(SystemCode.QUERY_CHECK_ERROR, "当前报表您不能进行审核（状态还在流转阶段）");
                }
            }

            // 修改报表的状态
            financeAuditMapper.consentOrFailFinance(financeId,
                    auditFinanceReq.getFailMsg(),
                    expectFinanceStatus);

            AxhFinanceLog axhFinanceLog = new AxhFinanceLog();

            //判断是审核通过还是不通过
            if (auditFinanceReq.getIsConsent().equals(1)) {
                axhFinanceLog.setRemark("同意审核");
                axhFinanceLog.setLogContent("【报表审核】用户" + dtUsersVo.getUsername() + "审核了该报表，状态为：已通过");
            } else if (auditFinanceReq.getIsConsent().equals(0)) {
                axhFinanceLog.setRemark(auditFinanceReq.getFailMsg());
                axhFinanceLog.setLogContent("【报表审核】用户" + dtUsersVo.getUsername() + "审核了该报表，状态为：驳回");
            }

            // 插入日志
            axhFinanceLog.setFinanceId(financeId);
            axhFinanceLog.setCurrentFinanceStatus(expectFinanceLogStatus);
            axhFinanceLog.setCommandUserId(dtUsersVo.getId());
            financeAuditMapper.addAuditLog(axhFinanceLog);
        }
    }

    @Override
    public TableData<FindAuditFinanceVo> findAuditFinance(FindAuditFinanceDto findAuditFinanceDto) throws SzException {
        findAuditFinanceDto.format();

        if (findAuditFinanceDto.getAreaType() == null) {
            // 查询当前用户应该能看到什么areaType
            List<DtNewsSort> sortParent = dtNewsService.findSortParent();
            if (!CollectionUtils.isEmpty(sortParent)) {
                StringJoiner sj = new StringJoiner(",");
                for (DtNewsSort dtNewsSort : sortParent) {
                    if (findAuditFinanceDto.getPageType().equals(1) && !dtNewsSort.getId().equals(AddressConstant.ZJ)) {
                        continue;
                    } else if (findAuditFinanceDto.getPageType().equals(2) && dtNewsSort.getId().equals(AddressConstant.ZJ)) {
                        continue;
                    }
                    sj.add(dtNewsSort.getId().toString());
                }
                findAuditFinanceDto.setAreaTypeStr(sj.toString());
            } else {
                findAuditFinanceDto.setAreaTypeStr("-1111");
            }
        } else {
            findAuditFinanceDto.setAreaTypeStr(findAuditFinanceDto.getAreaType() + "");
        }

        //获取当前登陆用户的信息
        DtUsersVo dtUsersVo = DtUsersVo.findCurrentUser();
        // 查询当前用户可看什么状态的报表
        String userAuditFinanceStatusStr = dtUsersVo.findUserAuditFinanceStatusStr(null, findAuditFinanceDto.getPageType());

        String userManageAreaId = dtUsersVo.findUserManageAllAddressId();
        Integer count = findAuditFinanceDto.getIsAlreadyProcess() == 0 ? financeAuditMapper.findFinanceAuditCount(findAuditFinanceDto,
                org.springframework.util.StringUtils.hasLength(userManageAreaId) ? userManageAreaId : null,
                userAuditFinanceStatusStr,
                findAuditFinanceDto.getMonth() == null ? null : MD5Utils.monthLastDayTime(DateUtil.parse(findAuditFinanceDto.getMonth(), "yyyy-MM")))
                : financeAuditMapper.findFinanceAuditCount2(findAuditFinanceDto,
                org.springframework.util.StringUtils.hasLength(userManageAreaId) ? userManageAreaId : null,
                userAuditFinanceStatusStr,
                findAuditFinanceDto.getMonth() == null ? null : MD5Utils.monthLastDayTime(DateUtil.parse(findAuditFinanceDto.getMonth(), "yyyy-MM")),
                dtUsersVo.getId());

        List<FindAuditFinanceVo> findAuditFinanceVos = null;
        if (count != null && count > 0) {
            findAuditFinanceVos = findAuditFinanceDto.getIsAlreadyProcess() == 0 ? financeAuditMapper.findFinanceAudit(findAuditFinanceDto,
                    org.springframework.util.StringUtils.hasLength(userManageAreaId) ? userManageAreaId : null,
                    userAuditFinanceStatusStr,
                    findAuditFinanceDto.getMonth() == null ? null : MD5Utils.monthLastDayTime(DateUtil.parse(findAuditFinanceDto.getMonth(), "yyyy-MM"))) :
                    financeAuditMapper.findFinanceAudit2(findAuditFinanceDto,
                            org.springframework.util.StringUtils.hasLength(userManageAreaId) ? userManageAreaId : null,
                            userAuditFinanceStatusStr,
                            findAuditFinanceDto.getMonth() == null ? null : MD5Utils.monthLastDayTime(DateUtil.parse(findAuditFinanceDto.getMonth(), "yyyy-MM")),
                            dtUsersVo.getId());
            if (!CollectionUtils.isEmpty(findAuditFinanceVos)) {
                for (FindAuditFinanceVo findAuditFinanceVo : findAuditFinanceVos) {
                    findAuditFinanceVo.setPlan("1".equals(findAuditFinanceVo.getIsPublic() + "") ? "已公开" : TwoLevelAuditConstant.findPlanStr(findAuditFinanceVo.getCurrentStatus()));
                }
            }
        }
        return new TableData<>(findAuditFinanceVos, count);
    }

    @Override
    public FinanceDetailVo findAuditFinanceDetail(Integer financeId) throws SzException {

        // 查询基本信息
        AxhFinancePo axhFinancePo = axhFinanceDao.selectByPrimaryKey(financeId);
        if (axhFinancePo == null) {
            throw new SzException(SystemCode.QUERY_CHECK_ERROR, "报表不存在");
        }
        FindAuditFinanceVo auditFinanceVo = new FindAuditFinanceVo();
        BeanUtils.copyProperties(axhFinancePo, auditFinanceVo);
        auditFinanceVo.setPlan("1".equals(auditFinanceVo.getIsPublic() + "") ? "已公开" : TwoLevelAuditConstant.findPlanStr(auditFinanceVo.getCurrentStatus()));

        FinanceDetailVo.FinanceDetailVoBuilder financeDetailVoBuilder = FinanceDetailVo.builder()
                .auditFinanceVo(auditFinanceVo)
                .failMsg(org.springframework.util.StringUtils.hasLength(axhFinancePo.getCurrentFailMsg()) ? axhFinancePo.getCurrentFailMsg() : null);
        DtUsersVo dtUsersVo = DtUsersVo.findCurrentUser();

        if (org.springframework.util.StringUtils.hasLength(axhFinancePo.getSourceFileUrl())) {
            int lastIndexOf = axhFinancePo.getSourceFileUrl().lastIndexOf(".");

            if (lastIndexOf > 0) {
                financeDetailVoBuilder.fileSuffix(axhFinancePo.getSourceFileUrl().substring(lastIndexOf + 1));
            }
        }

        // 查询报表的日志信息
        List<AxhAuditFinanceLogVo> financeLog = findFinanceLog(auditFinanceVo, financeId);
        financeDetailVoBuilder.axhAuditFinanceLogVos(financeLog)
                .btn(initFinanceBtn(dtUsersVo, axhFinancePo));

        return financeDetailVoBuilder.build();
    }

    /**
     * 构建当前用户对报表按钮的状态
     *
     * @param dtUsersVo
     * @param axhFinancePo
     * @return
     */
    private FinanceDetailVo.Btn initFinanceBtn(DtUsersVo dtUsersVo, AxhFinancePo axhFinancePo) {


        FinanceDetailVo.Btn.BtnBuilder builder = FinanceDetailVo.Btn.builder();
        Integer userMaxRole = dtUsersVo.getUserMaxRole();

        if (axhFinancePo.getAreaType().equals(AddressConstant.ZJ)) {

            if (dtUsersVo.getId().equals(axhFinancePo.getCreateUserId())) {
                builder.isSubmit(axhFinancePo.getCurrentStatus().equals(OneLevelAuditConstant.DRAFT) ? 1 : 0);
                builder.isSave(axhFinancePo.getCurrentStatus().equals(OneLevelAuditConstant.DRAFT) ? 1 : 0);
                builder.isDel(axhFinancePo.getCurrentStatus().equals(OneLevelAuditConstant.DRAFT) ? 1 : 0);
                builder.isCaoGao(axhFinancePo.getCurrentStatus().equals(OneLevelAuditConstant.FAIL) ? 1 : 0);
                builder.isPublic(axhFinancePo.getCurrentStatus().equals(OneLevelAuditConstant.CONSENT) && axhFinancePo.getIsPublic() == 0 ? 1 : 0);
            } else if (userMaxRole.equals(SystemRoleConstant.Z_CZS_SZ) && axhFinancePo.getCurrentStatus().equals(OneLevelAuditConstant.SUBMIT_AUDIT)) {
                builder.isSuccess(1);
                builder.isTurn(1);
            }
        } else {
            if (dtUsersVo.getId().equals(axhFinancePo.getCreateUserId())) {
                builder.isSubmit(axhFinancePo.getCurrentStatus().equals(TwoLevelAuditConstant.DRAFT) ? 1 : 0);
                builder.isSave(axhFinancePo.getCurrentStatus().equals(TwoLevelAuditConstant.DRAFT) ? 1 : 0);
                builder.isDel(axhFinancePo.getCurrentStatus().equals(TwoLevelAuditConstant.DRAFT) ? 1 : 0);
                builder.isPublic(axhFinancePo.getCurrentStatus().equals(TwoLevelAuditConstant.TWO_CONSENT) && axhFinancePo.getIsPublic() == 0 ? 1 : 0);
                builder.isCaoGao(axhFinancePo.getCurrentStatus().equals(TwoLevelAuditConstant.ONE_FAIL) ? 1 : 0);
            } else if (userMaxRole.equals(SystemRoleConstant.Z_JGZ_CY) &&
                    (axhFinancePo.getCurrentStatus().equals(TwoLevelAuditConstant.SUBMIT_AUDIT) || axhFinancePo.getCurrentStatus().equals(TwoLevelAuditConstant.TWO_FAIL))) {
                builder.isSuccess(1);
                builder.isTurn(1);
            } else if (userMaxRole.equals(SystemRoleConstant.Z_JGZ_ZZ) && axhFinancePo.getCurrentStatus().equals(TwoLevelAuditConstant.ONE_CONSENT)) {
                builder.isSuccess(1);
                builder.isTurn(1);
            } else if (userMaxRole.equals(SystemRoleConstant.Z_CZS_CY) &&
                    (axhFinancePo.getCurrentStatus().equals(TwoLevelAuditConstant.SUBMIT_AUDIT) || axhFinancePo.getCurrentStatus().equals(TwoLevelAuditConstant.TWO_FAIL))) {
                builder.isSuccess(1);
                builder.isTurn(1);
            } else if (userMaxRole.equals(SystemRoleConstant.Z_CZS_SZ) && axhFinancePo.getCurrentStatus().equals(TwoLevelAuditConstant.ONE_CONSENT)) {
                builder.isSuccess(1);
                builder.isTurn(1);
            }
        }


        return builder.build();
    }


    public List<AxhAuditFinanceLogVo> findFinanceLog(FindAuditFinanceVo auditFinanceVo, Integer financeId) {
        List<AxhAuditFinanceLogVo> axhAuditFinanceLogVos = new ArrayList<>();

        // 查询报表日志信息
        if (auditFinanceVo.getAreaType().equals(AddressConstant.ZJ)) {

            // 判断当前的报表状态是什么
            if (auditFinanceVo.getCurrentStatus().equals(OneLevelAuditConstant.DRAFT)) {
                AxhAuditFinanceLogVo axhAuditFinanceLogVo = new AxhAuditFinanceLogVo();
                axhAuditFinanceLogVo.setUsername("等待提交");
                axhAuditFinanceLogVo.setWait(0);
                axhAuditFinanceLogVos.add(axhAuditFinanceLogVo);


                AxhAuditFinanceLogVo axhAuditFinanceLogVo2 = new AxhAuditFinanceLogVo();
                axhAuditFinanceLogVo2.setUsername("镇财政所所长");
                axhAuditFinanceLogVo2.setWait(1);
                axhAuditFinanceLogVos.add(axhAuditFinanceLogVo2);

                AxhAuditFinanceLogVo axhAuditFinanceLogVo3 = new AxhAuditFinanceLogVo();
                axhAuditFinanceLogVo2.setUsername("等待发布");
                axhAuditFinanceLogVo2.setWait(1);
                axhAuditFinanceLogVos.add(axhAuditFinanceLogVo3);
            } else if (auditFinanceVo.getCurrentStatus().equals(OneLevelAuditConstant.SUBMIT_AUDIT)) {

                AxhAuditFinanceLogVo financeLog = financeMapper.findFinanceLog(financeId, FinanceAuditLogStep.SEND_AUDIT.VAL);
                axhAuditFinanceLogVos.add(financeLog);

                AxhAuditFinanceLogVo axhAuditFinanceLogVo2 = new AxhAuditFinanceLogVo();
                axhAuditFinanceLogVo2.setUsername("镇财政所所长");
                axhAuditFinanceLogVo2.setWait(0);
                axhAuditFinanceLogVos.add(axhAuditFinanceLogVo2);

                AxhAuditFinanceLogVo axhAuditFinanceLogVo3 = new AxhAuditFinanceLogVo();
                axhAuditFinanceLogVo3.setUsername("等待发布");
                axhAuditFinanceLogVo3.setWait(1);
                axhAuditFinanceLogVos.add(axhAuditFinanceLogVo3);
            } else if (auditFinanceVo.getCurrentStatus().equals(OneLevelAuditConstant.PUBLIC) || auditFinanceVo.getIsPublic() == 1) {


                AxhAuditFinanceLogVo financeLog = financeMapper.findFinanceLog(financeId, FinanceAuditLogStep.SEND_AUDIT.VAL);
                axhAuditFinanceLogVos.add(financeLog);

                AxhAuditFinanceLogVo financeLog2 = financeMapper.findFinanceLog(financeId, FinanceAuditLogStep.ONE_LEVEL_CONSENT.VAL);
                axhAuditFinanceLogVos.add(financeLog2);

                AxhAuditFinanceLogVo financeLog3 = financeMapper.findFinanceLog(financeId, FinanceAuditLogStep.PUBLIC.VAL);
                axhAuditFinanceLogVos.add(financeLog3);
            } else if (auditFinanceVo.getCurrentStatus().equals(OneLevelAuditConstant.CONSENT) || auditFinanceVo.getCurrentStatus().equals(OneLevelAuditConstant.FAIL)) {

                AxhAuditFinanceLogVo financeLog = financeMapper.findFinanceLog(financeId, FinanceAuditLogStep.SEND_AUDIT.VAL);
                axhAuditFinanceLogVos.add(financeLog);

                AxhAuditFinanceLogVo financeLog2 = null;

                if (auditFinanceVo.getCurrentStatus().equals(OneLevelAuditConstant.CONSENT)) {
                    financeLog2 = financeMapper.findFinanceLog(financeId, FinanceAuditLogStep.ONE_LEVEL_CONSENT.VAL);
                } else {
                    financeLog2 = financeMapper.findFinanceLog(financeId, FinanceAuditLogStep.ONE_LEVEL_FAIL.VAL);
                }

                axhAuditFinanceLogVos.add(financeLog2);

                AxhAuditFinanceLogVo axhAuditFinanceLogVo3 = new AxhAuditFinanceLogVo();
                axhAuditFinanceLogVo3.setUsername("等待发布");
                if (auditFinanceVo.getCurrentStatus().equals(OneLevelAuditConstant.FAIL)) {
                    axhAuditFinanceLogVo3.setWait(1);
                } else {
                    axhAuditFinanceLogVo3.setWait(0);
                }

                axhAuditFinanceLogVos.add(axhAuditFinanceLogVo3);
            }


        } else {

            String twoTitle = "";
            String threeTitle = "";
            if (auditFinanceVo.getAreaType().equals(AddressConstant.CUN)) {
                twoTitle = "镇经管站成员";
                threeTitle = "镇经管站站长";
            } else {
                twoTitle = "镇财经所成员";
                threeTitle = "镇财经所所长";
            }
            if (auditFinanceVo.getCurrentStatus().equals(TwoLevelAuditConstant.DRAFT)) {
                AxhAuditFinanceLogVo axhAuditFinanceLogVo = new AxhAuditFinanceLogVo();
                axhAuditFinanceLogVo.setUsername("等待提交");
                axhAuditFinanceLogVo.setWait(0);
                axhAuditFinanceLogVos.add(axhAuditFinanceLogVo);


                AxhAuditFinanceLogVo axhAuditFinanceLogVo2 = new AxhAuditFinanceLogVo();
                axhAuditFinanceLogVo2.setUsername(twoTitle);
                axhAuditFinanceLogVo2.setWait(1);
                axhAuditFinanceLogVos.add(axhAuditFinanceLogVo2);

                AxhAuditFinanceLogVo axhAuditFinanceLogVo3 = new AxhAuditFinanceLogVo();
                axhAuditFinanceLogVo3.setUsername(threeTitle);
                axhAuditFinanceLogVo3.setWait(1);
                axhAuditFinanceLogVos.add(axhAuditFinanceLogVo3);

                AxhAuditFinanceLogVo axhAuditFinanceLogVo4 = new AxhAuditFinanceLogVo();
                axhAuditFinanceLogVo4.setUsername("等待发布");
                axhAuditFinanceLogVo4.setWait(1);
                axhAuditFinanceLogVos.add(axhAuditFinanceLogVo4);
            } else if (auditFinanceVo.getCurrentStatus().equals(TwoLevelAuditConstant.SUBMIT_AUDIT)) {

                AxhAuditFinanceLogVo axhAuditFinanceLogVo = financeMapper.findFinanceLog(financeId, FinanceAuditLogStep.SEND_AUDIT.VAL);
                axhAuditFinanceLogVos.add(axhAuditFinanceLogVo);

                AxhAuditFinanceLogVo axhAuditFinanceLogVo2 = new AxhAuditFinanceLogVo();
                axhAuditFinanceLogVo2.setUsername(twoTitle);
                axhAuditFinanceLogVo2.setWait(0);
                axhAuditFinanceLogVos.add(axhAuditFinanceLogVo2);

                AxhAuditFinanceLogVo axhAuditFinanceLogVo3 = new AxhAuditFinanceLogVo();
                axhAuditFinanceLogVo3.setUsername(threeTitle);
                axhAuditFinanceLogVo3.setWait(1);
                axhAuditFinanceLogVos.add(axhAuditFinanceLogVo3);

                AxhAuditFinanceLogVo axhAuditFinanceLogVo4 = new AxhAuditFinanceLogVo();
                axhAuditFinanceLogVo4.setUsername("等待发布");
                axhAuditFinanceLogVo4.setWait(1);
                axhAuditFinanceLogVos.add(axhAuditFinanceLogVo4);
            } else if (auditFinanceVo.getCurrentStatus().equals(TwoLevelAuditConstant.ONE_CONSENT) || auditFinanceVo.getCurrentStatus().equals(TwoLevelAuditConstant.ONE_FAIL)) {

                AxhAuditFinanceLogVo axhAuditFinanceLogVo = financeMapper.findFinanceLog(financeId, FinanceAuditLogStep.SEND_AUDIT.VAL);
                axhAuditFinanceLogVos.add(axhAuditFinanceLogVo);

                if (auditFinanceVo.getCurrentStatus().equals(TwoLevelAuditConstant.ONE_CONSENT)) {

                    AxhAuditFinanceLogVo axhAuditFinanceLogVo2 = financeMapper.findFinanceLog(financeId, FinanceAuditLogStep.ONE_LEVEL_CONSENT.VAL);
                    axhAuditFinanceLogVos.add(axhAuditFinanceLogVo2);
                } else {
                    AxhAuditFinanceLogVo axhAuditFinanceLogVo2 = financeMapper.findFinanceLog(financeId, FinanceAuditLogStep.ONE_LEVEL_FAIL.VAL);
                    axhAuditFinanceLogVos.add(axhAuditFinanceLogVo2);
                }
                AxhAuditFinanceLogVo axhAuditFinanceLogVo3 = new AxhAuditFinanceLogVo();
                axhAuditFinanceLogVo3.setUsername(threeTitle);
                if (auditFinanceVo.getCurrentStatus().equals(TwoLevelAuditConstant.ONE_FAIL)) {
                    axhAuditFinanceLogVo3.setWait(1);
                } else {
                    axhAuditFinanceLogVo3.setWait(0);
                }
                axhAuditFinanceLogVos.add(axhAuditFinanceLogVo3);

                AxhAuditFinanceLogVo axhAuditFinanceLogVo4 = new AxhAuditFinanceLogVo();
                axhAuditFinanceLogVo4.setUsername("等待发布");
                axhAuditFinanceLogVo4.setWait(1);
                axhAuditFinanceLogVos.add(axhAuditFinanceLogVo4);
            } else if (auditFinanceVo.getCurrentStatus().equals(OneLevelAuditConstant.PUBLIC) || auditFinanceVo.getIsPublic() == 1) {

                AxhAuditFinanceLogVo axhAuditFinanceLogVo = financeMapper.findFinanceLog(financeId, FinanceAuditLogStep.SEND_AUDIT.VAL);
                axhAuditFinanceLogVos.add(axhAuditFinanceLogVo);

                AxhAuditFinanceLogVo axhAuditFinanceLogVo2 = financeMapper.findFinanceLog(financeId, FinanceAuditLogStep.ONE_LEVEL_CONSENT.VAL);
                axhAuditFinanceLogVos.add(axhAuditFinanceLogVo2);

                AxhAuditFinanceLogVo axhAuditFinanceLogVo3 = financeMapper.findFinanceLog(financeId, FinanceAuditLogStep.TWO_LEVEL_CONSENT.VAL);
                axhAuditFinanceLogVos.add(axhAuditFinanceLogVo3);

                AxhAuditFinanceLogVo axhAuditFinanceLogVo4 = financeMapper.findFinanceLog(financeId, FinanceAuditLogStep.PUBLIC.VAL);
                axhAuditFinanceLogVos.add(axhAuditFinanceLogVo4);

            } else if (auditFinanceVo.getCurrentStatus().equals(TwoLevelAuditConstant.TWO_CONSENT) || auditFinanceVo.getCurrentStatus().equals(TwoLevelAuditConstant.TWO_FAIL)) {

                AxhAuditFinanceLogVo axhAuditFinanceLogVo = financeMapper.findFinanceLog(financeId, FinanceAuditLogStep.SEND_AUDIT.VAL);
                axhAuditFinanceLogVos.add(axhAuditFinanceLogVo);

                AxhAuditFinanceLogVo axhAuditFinanceLogVo2 = financeMapper.findFinanceLog(financeId, FinanceAuditLogStep.ONE_LEVEL_CONSENT.VAL);
                axhAuditFinanceLogVos.add(axhAuditFinanceLogVo2);

                if (auditFinanceVo.getCurrentStatus().equals(TwoLevelAuditConstant.TWO_CONSENT)) {

                    AxhAuditFinanceLogVo axhAuditFinanceLogVo3 = financeMapper.findFinanceLog(financeId, FinanceAuditLogStep.TWO_LEVEL_CONSENT.VAL);
                    axhAuditFinanceLogVos.add(axhAuditFinanceLogVo3);
                } else {
                    AxhAuditFinanceLogVo axhAuditFinanceLogVo3 = financeMapper.findFinanceLog(financeId, FinanceAuditLogStep.TWO_LEVEL_FAIL.VAL);
                    axhAuditFinanceLogVos.add(axhAuditFinanceLogVo3);
                }

                AxhAuditFinanceLogVo axhAuditFinanceLogVo4 = new AxhAuditFinanceLogVo();
                axhAuditFinanceLogVo4.setUsername("等待发布");
                if (auditFinanceVo.getCurrentStatus().equals(TwoLevelAuditConstant.TWO_FAIL)) {
                    axhAuditFinanceLogVo4.setWait(1);
                } else {
                    axhAuditFinanceLogVo4.setWait(0);
                }
                axhAuditFinanceLogVos.add(axhAuditFinanceLogVo4);
            }
        }

        return axhAuditFinanceLogVos;
    }
}
